package com.momoauth.api_client.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.momoauth.api_client.entity.System_Log;
import com.momoauth.api_client.mapper.SystemLogMapper;
import com.momoauth.common.core.result.ResponseResurt;
import com.momoauth.common.security.annotation.RequiresRoles;
import com.momoauth.common.security.enumeration.Logical;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/log")
@Api(tags = "系统操作日志")
@RequiresRoles(value = {"超级管理员","普通管理员"}, logical = Logical.OR)
public class SystemLogController {

    @Resource
    SystemLogMapper systemLogMapper;

    /**
     * 系统操作日志列表
     * @param system_log
     * @return
     */
    @ApiOperation(value = "系统操作日志列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页数", required = true)
    })
    @RequestMapping(value = "/getSystemLogList", method = RequestMethod.GET)
    public ResponseResurt getSystemLogList(System_Log system_log) {
        Page<System_Log> page = new Page<>(system_log.getCurrentPage(),system_log.getPageSize());
        QueryWrapper<System_Log> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("logId"); //按主键倒序排序
        page.setRecords(systemLogMapper.getSystemLogList(page,queryWrapper));
        return ResponseResurt.success().data(page);
    }

    /**
     * 系统操作日志详情
     * @param system_log
     * @return
     */
    @ApiOperation(value = "系统操作日志详情")
    @ApiImplicitParam(name = "logId", value = "日志ID（主键）", required = true)
    @RequestMapping(value = "/getSystemLogById", method = RequestMethod.GET)
    public ResponseResurt getSystemLogById(System_Log system_log) {
        system_log = systemLogMapper.selectById(system_log.getLogId());
        return ResponseResurt.success().data(system_log);
    }
}
